package com.lzh.lzhblog.controller;

import com.google.gson.Gson;
import com.lzh.lzhframework.utils.SecurityUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author luzhiheng
 * @Date 2023/11/6 17:51
 */
@RestController
@RequestMapping("/system")
public class SystemController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/testMq")
    public String sendMsg(Long receiverId) {
        Long userId = SecurityUtils.getUserId();
        if (userId == null) {
            return "no login";
        }
        Gson gson = new Gson();
        Map<String, Object> map = new HashMap<>();
        map.put("role", "admin");
        map.put("sendUserId", userId);
        map.put("receiveUserId", receiverId);
        rabbitTemplate.convertAndSend("testExchange10", "test.user", gson.toJson(map));
        return "success";
    }
}
